<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/assets/css/layui.css">
    <link rel="stylesheet" href="/static/assets/css/login.css">
    <link rel="icon" href="/static/favicon.ico">
    <title>人才简历管理后台</title>
</head>
<body class="login-wrap">
    <div class="login-container">
        <form class="login-form" id="loginForm"  action="/login" METHOD="post">
            <div class="input-group">
                <h3 style="text-align: center;color: #2c2e2f">人才信息管理系统后台</h3>
                <input type="text" id="username"  name="username" class="input-field">
                <font color="red" th:text="${msg}"></font>
                <label for="username" class="input-label">
                    <span class="label-title">用户名</span>
                </label>
            </div>
            <div class="input-group">
                <input type="password" id="password" name="password" class="input-field">
                <input type="hidden" id="token" name="token">
                <label for="password" class="input-label">
                    <span class="label-title">密码</span>
                </label>
            </div>
            <button type="button"  id="login_btn" class="login-button">登录<i class="ai ai-enter"></i></button>
        </form>
    </div>
</body>
<script type="text/javascript" th:src="@{/static/assets/layui.js}"></script>
<script type="text/javascript" th:src="@{/static/js/jquery.min.js}"></script>
<script >
    $(function () {
        $("#login_btn").click(function () {
            var username =$("#username").val();
            var password =$("#password").val();
            $.ajax({
                url: "/getToken",
                async:false,
                data:JSON.stringify({'username':username,'password':password}),
                type: "POST",
                contentType:'application/json;charset=UTF-8',
                dataType:'Json',
                success:function (data) {
                    //成功获取Token
                    /*alert(JSON.stringify(data.token))*/
                    $("#token").val(JSON.stringify(data.token))
                   /*$("#username").val(username);
                    $("#password").val(password);*/
                    $("#loginForm").submit();
                    /* $("#loginForm").submit();*/



                    /* 提交表单*/
                    /*    $.ajax({
                                 url: "/login",
                                 type: "POST",
                                 data:JSON.stringify({'username':username,'password':password}),
                                 headers:{'token':JSON.stringify(data.token)},
                                 dataType:'json',
                                 contentType:'application/json;charset=UTF-8',
                                 success:function (data) {
                                    alert(JSON.stringify(data))
                                     alert("登录成功!")
                                 },
                                 error:function(){
                                     alert("回調失敗！！");
                                 }
                             });*/
                },
                error:function(){
                    alert("登录失败！！");
                }
            });

        });
    })
</script>
</html>